<template>
  <div>
       <!-- 新增修改表单 -->
      <el-dialog :title="textMap[dialogStatus]" :visible.sync="DialogFormVisibleCom" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="100px" style="width: 90%; margin:10px auto;">
      
        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 期限方案编号 -->
            <el-form-item label="期限方案编号：" prop="tp_code">
              <el-input v-model="formSubmitDataCom.tp_code" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <!-- 期限方案名称 -->
            <el-form-item label="期限方案名称：" prop="tp_name">
              <el-input v-model="formSubmitDataCom.tp_name"  />
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <!-- 所属法人 -->
            <el-form-item label="所属法人" prop="lp_code">
              <el-select v-model="formSubmitDataCom.lp_code" class="filter-item" placeholder="Please select"  v-bind:disabled='formSubmitData.id!=""'>
                <el-option v-for="item in lpOptions" :key="item.lp_code" :label="item.lp_name" :value="item.lp_code" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input type="textarea" v-model="formSubmitDataCom.remark"  placeholder="Please select"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      

      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>




export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props:{
    dialogFormVisible:{
        type: Boolean,
        default: false
    },
    dialogStatus:{
        type: String,
    },
    
    formSubmitData:{
      type: Object,
      default: function() {
        return {
          id: undefined,
          tp_code: "",
          tp_name: '',
          lp_code: '',
          remark: '',
        }
      }
    },
    // 法人selectData
    lpOptions:{
      type:Array
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
          update: '修改',
          create: '新增'
      },
      rules: {
        tp_code: [{ required: true, message: '期限方案编号必填', trigger: 'change' }],
        tp_name: [{ required: true, message: '期限方案名称必填', trigger: 'change' }],
        lp_code: [{ required: true, message: '所属法人必填', trigger: 'change' }],
      },
      
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom:{
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom:{
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
     resetFormData(){
      this.$emit('resetFormDataEmit')
    },
      findlp() {
      this.$refs['datalp'].validate((valid) => {
        if (valid) {
          this.$emit('findlp')
          
        }
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
          
        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitDataCom, "_XID");
          this.$delete(this.formSubmitDataCom, "lp_name");
          const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
          
        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>
  
</style>